<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.application.component.model');

/**
* liniomenu model Class for linio Component
* 
* @package    joomla.administrator.components.linio.models
* @subpackage components
* @author MAVLSoft - joomla! Component Creator 1.0
* @version 1.0
* @link http://www.mavlsoft.com/joomlacreator
* @license GNU General Public License version 3 or later; see http://www.gnu.org/copyleft/gpl.html
*/
class linioModelliniomenu extends JModel
{
/**
 * Constructor that retrieves the ID from the request
 *
 * @access    public
 * @return    void
 */
function __construct()
{
	parent::__construct();
 
	$this->setId(JRequest::getVar('id'));
}

/**
 * Method to set the liniomenu identifier
 *
 * @access    public
 * @param    string id identifier
 * @return    void
 */
function setId($id)
{
	// Set id and wipe data
	$this->_id		= $id;
	$this->_data	= null;
}

/**
 * Method to get a liniomenu object
 * @return object with data
 */
 
function &getData()
{
	// Load the data
	if (empty( $this->_data )) {
		$query = " SELECT * FROM #__liniomenu".
				"  WHERE id = '".$this->_id."'".
				";";
		$this->_db->setQuery( $query );
		$this->_data = $this->_db->loadObject();
	}
	if (!$this->_data) {
		$this->_data = new stdClass();
		$this->_data->id = null;
		$this->_data->parentid = null;
		$this->_data->description = null;
	}
	return $this->_data;
}

/**
* Method to store a record
*
* @access    public
* @return    boolean    True on success
*/
function store()
{
	$row =& $this->getTable();
 
	$data = JRequest::get( 'post' );
	// Bind the form fields to the liniomenu table
	if (!$row->bind($data)) {
		$this->setError($this->_db->getErrorMsg());
		return false;
	}
 
	// Make sure the liniomenu record is valid
	if (!$row->check()) {
		$this->setError($this->_db->getErrorMsg());
		return false;
	}
 
	// Store the liniomenu table to the database
	if (!$row->store()) {
		$this->setError($this->_db->getErrorMsg());
		return false;
	}
 
	return true;
}

/**
 * Method to delete record(s)
 *
 * @access    public
 * @return    boolean    True on success
 */
function delete()
{
	$cids = JRequest::getVar( 'cid', array(0), 'post', 'array' );
	$row =& $this->getTable();
 
	foreach($cids as $cid) {
		if (!$row->delete( $cid )) {
			$this->setError( $row->getErrorMsg() );
			return false;
		}
	}
 
	return true;
}

/**
*
* Obtener el total de registros de la tabla liniomenu
*/
function getTotalRecs(){
	$db =&JFactory::getDBO();
	$query = 'SELECT COUNT(*) FROM #__liniomenu';
	$db->setQuery($query);
	return $db->loadResult();
}

/**
* Metodo para consultar todos los registros de la tabla liniomenu
* @return object with data
*/
function consulta($limitstart=0,$limit=0)
{
	$datos;
	$query = "SELECT * FROM #__liniomenu";
	$datos = $this->_getList( $query, $limitstart, $limit );
	return $datos;
}
}
?>